package core;

import java.awt.Color;
import java.util.Vector;

import core.actions.*;
import core.mountedWeapons.GenericPistol;
import core.units.HeroUnit;
import core.units.Unit;

public class PlayerData {
	
	private ActionMap<Action> mainActionMap = new ActionMap<Action>();
	private ActionSet actionSet = new ActionSet(GameOptions.modName);
	private char key;
	private Color playerColor = Color.magenta;
	
	private Vector<Unit> units = new Vector<Unit>();  // Customizable main units
	Unit selectedUnit;
	
	
	public PlayerData(char key){
		this.key=key;
		
		//mainActionMap.add(new MoveHero());
		setDefaultActionMap();
		//units.add(new HeroUnit(0, 0, null));
		//units.add(new HeroUnit(0, 0, null));
		
		//selectedUnit=units.get(0);
	}

	public ActionMap<Action> getMainActionMap(){
		return mainActionMap;
	}
	
	public void linkToPlayer(Player p){
		for(Action a : mainActionMap.getAllActions()){
			if(a!=null)
				a.setOwner(p);
		}
		for(Unit u : units){
			u.linkToPlayer(p);
		}
	}
	
	public void setDefaultActionMap(){
		
		mainActionMap.clear();
		
		
		//mainActionMap.add(new FireMortar());
		mainActionMap.add(new AddMachinegun());
		
		mainActionMap.add(new SpawnDefaultUnit());
		mainActionMap.add(new FireMissile());
		mainActionMap.add(new MoveHero());
		mainActionMap.add(new OrderAllMove());		
		mainActionMap.add(new SpawnArtilleryBuggy());
		mainActionMap.add(new FireShotgun());
		mainActionMap.add(new FireLaser());
		mainActionMap.add(new FireSniper());
    	
	}

	public char getKey() {
		return key;
	}

	public ActionMap<Action> getActionMap(){
		return selectedUnit.getActionMap();
	}


	public void setPlayerColor(Color playerColor) {
		this.playerColor = playerColor;
	}



	public Color getPlayerColor() {
		return playerColor;
	}
	public ActionSet getActionSet(){
		return actionSet;
	}
	public Vector<Unit> getUnits(){
		return units;
	}
	/**
	 * Does not link the unit to the player by itself
	 * @param u
	 */
	public void addUnit(Unit u){
		units.add(u);
	}
	public void selectNextUnit(){
		int unitIndex = units.indexOf(selectedUnit);
		unitIndex++;
		if(units.size() <= unitIndex)
			unitIndex = 0;
		selectedUnit= units.get(unitIndex);
	}
	
}
